// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyMachineProfile.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <PyLaunchProfile.h>

// ****************************************************************************
// Module: PyMachineProfile
//
// Purpose:
//   This class contains information about a host for a remote VisIt engine.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a MachineProfile.
//
struct MachineProfileObject
{
    PyObject_HEAD
    MachineProfile *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewMachineProfile(int);
std::string
PyMachineProfile_ToString(const MachineProfile *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    snprintf(tmpStr, 1000, "%shost = \"%s\"\n", prefix, atts->GetHost().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%suserName = \"%s\"\n", prefix, atts->GetUserName().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%spassword = \"%s\"\n", prefix, atts->GetPassword().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%shostAliases = \"%s\"\n", prefix, atts->GetHostAliases().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%shostNickname = \"%s\"\n", prefix, atts->GetHostNickname().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sdirectory = \"%s\"\n", prefix, atts->GetDirectory().c_str());
    str += tmpStr;
    if(atts->GetShareOneBatchJob())
        snprintf(tmpStr, 1000, "%sshareOneBatchJob = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sshareOneBatchJob = 0\n", prefix);
    str += tmpStr;
    if(atts->GetSshPortSpecified())
        snprintf(tmpStr, 1000, "%ssshPortSpecified = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%ssshPortSpecified = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%ssshPort = %d\n", prefix, atts->GetSshPort());
    str += tmpStr;
    if(atts->GetSshCommandSpecified())
        snprintf(tmpStr, 1000, "%ssshCommandSpecified = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%ssshCommandSpecified = 0\n", prefix);
    str += tmpStr;
    {   const stringVector &sshCommand = atts->GetSshCommand();
        snprintf(tmpStr, 1000, "%ssshCommand = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < sshCommand.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", sshCommand[i].c_str());
            str += tmpStr;
            if(i < sshCommand.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    if(atts->GetUseGateway())
        snprintf(tmpStr, 1000, "%suseGateway = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%suseGateway = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sgatewayHost = \"%s\"\n", prefix, atts->GetGatewayHost().c_str());
    str += tmpStr;
    const char *clientHostDetermination_names = "MachineName, ManuallySpecified, ParsedFromSSHCLIENT";
    switch (atts->GetClientHostDetermination())
    {
      case MachineProfile::MachineName:
          snprintf(tmpStr, 1000, "%sclientHostDetermination = %sMachineName  # %s\n", prefix, prefix, clientHostDetermination_names);
          str += tmpStr;
          break;
      case MachineProfile::ManuallySpecified:
          snprintf(tmpStr, 1000, "%sclientHostDetermination = %sManuallySpecified  # %s\n", prefix, prefix, clientHostDetermination_names);
          str += tmpStr;
          break;
      case MachineProfile::ParsedFromSSHCLIENT:
          snprintf(tmpStr, 1000, "%sclientHostDetermination = %sParsedFromSSHCLIENT  # %s\n", prefix, prefix, clientHostDetermination_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%smanualClientHostName = \"%s\"\n", prefix, atts->GetManualClientHostName().c_str());
    str += tmpStr;
    if(atts->GetTunnelSSH())
        snprintf(tmpStr, 1000, "%stunnelSSH = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%stunnelSSH = 0\n", prefix);
    str += tmpStr;
    if(atts->GetMaximumNodesValid())
        snprintf(tmpStr, 1000, "%smaximumNodesValid = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%smaximumNodesValid = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaximumNodes = %d\n", prefix, atts->GetMaximumNodes());
    str += tmpStr;
    if(atts->GetMaximumProcessorsValid())
        snprintf(tmpStr, 1000, "%smaximumProcessorsValid = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%smaximumProcessorsValid = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaximumProcessors = %d\n", prefix, atts->GetMaximumProcessors());
    str += tmpStr;
    { // new scope
        int index = 0;
        // Create string representation of launchProfiles from atts.
        for(AttributeGroupVector::const_iterator pos = atts->GetLaunchProfiles().begin(); pos != atts->GetLaunchProfiles().end(); ++pos, ++index)
        {
            const LaunchProfile *current = (const LaunchProfile *)(*pos);
            snprintf(tmpStr, 1000, "GetLaunchProfiles(%d).", index);
            std::string objPrefix(prefix + std::string(tmpStr));
            str += PyLaunchProfile_ToString(current, objPrefix.c_str(), forLogging);
        }
        if(index == 0)
            str += "#launchProfiles does not contain any LaunchProfile objects.\n";
    }
    snprintf(tmpStr, 1000, "%sactiveProfile = %d\n", prefix, atts->GetActiveProfile());
    str += tmpStr;
    return str;
}

static PyObject *
MachineProfile_Notify(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_SetHost(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the host in the object.
    obj->data->SetHost(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetHost(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetHost().c_str());
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetUserName(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the userName in the object.
    obj->data->SetUserName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetUserName(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetUserName().c_str());
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetPassword(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the password in the object.
    obj->data->SetPassword(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetPassword(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetPassword().c_str());
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetHostAliases(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the hostAliases in the object.
    obj->data->SetHostAliases(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetHostAliases(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetHostAliases().c_str());
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetHostNickname(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the hostNickname in the object.
    obj->data->SetHostNickname(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetHostNickname(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetHostNickname().c_str());
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetDirectory(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the directory in the object.
    obj->data->SetDirectory(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetDirectory(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetDirectory().c_str());
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetShareOneBatchJob(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the shareOneBatchJob in the object.
    obj->data->SetShareOneBatchJob(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetShareOneBatchJob(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetShareOneBatchJob()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetSshPortSpecified(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the sshPortSpecified in the object.
    obj->data->SetSshPortSpecified(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetSshPortSpecified(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetSshPortSpecified()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetSshPort(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the sshPort in the object.
    obj->data->SetSshPort(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetSshPort(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetSshPort()));
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetSshCommandSpecified(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the sshCommandSpecified in the object.
    obj->data->SetSshCommandSpecified(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetSshCommandSpecified(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetSshCommandSpecified()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetSshCommand(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetSshCommand() = vec;
    // Mark the sshCommand in the object as modified.
    obj->data->SelectSshCommand();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetSshCommand(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    // Allocate a tuple the with enough entries to hold the sshCommand.
    const stringVector &sshCommand = obj->data->GetSshCommand();
    PyObject *retval = PyTuple_New(sshCommand.size());
    for(size_t i = 0; i < sshCommand.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(sshCommand[i].c_str()));
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetUseGateway(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the useGateway in the object.
    obj->data->SetUseGateway(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetUseGateway(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetUseGateway()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetGatewayHost(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the gatewayHost in the object.
    obj->data->SetGatewayHost(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetGatewayHost(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetGatewayHost().c_str());
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetClientHostDetermination(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid clientHostDetermination value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " MachineName";
        ss << ", ManuallySpecified";
        ss << ", ParsedFromSSHCLIENT";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the clientHostDetermination in the object.
    obj->data->SetClientHostDetermination(MachineProfile::ClientHostDetermination(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetClientHostDetermination(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetClientHostDetermination()));
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetManualClientHostName(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the manualClientHostName in the object.
    obj->data->SetManualClientHostName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetManualClientHostName(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetManualClientHostName().c_str());
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetTunnelSSH(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the tunnelSSH in the object.
    obj->data->SetTunnelSSH(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetTunnelSSH(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetTunnelSSH()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetMaximumNodesValid(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the maximumNodesValid in the object.
    obj->data->SetMaximumNodesValid(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetMaximumNodesValid(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetMaximumNodesValid()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetMaximumNodes(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the maximumNodes in the object.
    obj->data->SetMaximumNodes(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetMaximumNodes(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetMaximumNodes()));
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetMaximumProcessorsValid(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the maximumProcessorsValid in the object.
    obj->data->SetMaximumProcessorsValid(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetMaximumProcessorsValid(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetMaximumProcessorsValid()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MachineProfile_SetMaximumProcessors(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the maximumProcessors in the object.
    obj->data->SetMaximumProcessors(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetMaximumProcessors(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetMaximumProcessors()));
    return retval;
}

/*static*/ PyObject *
MachineProfile_GetLaunchProfiles(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    int index = -1;
    if (args == NULL)
        return PyErr_Format(PyExc_NameError, "Use .GetLaunchProfiles(int index) to get a single entry");
    if (!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "arg must be a single integer index");
    if (index < 0 || (size_t)index >= obj->data->GetLaunchProfiles().size())
        return PyErr_Format(PyExc_ValueError, "index out of range");

    // Since the new object will point to data owned by the this object,
    // we need to increment the reference count.
    Py_INCREF(self);

    PyObject *retval = PyLaunchProfile_Wrap(&obj->data->GetLaunchProfiles(index));
    // Set the object's parent so the reference to the parent can be decref'd
    // when the child goes out of scope.
    PyLaunchProfile_SetParent(retval, self);

    return retval;
}

PyObject *
MachineProfile_GetNumLaunchProfiles(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    return PyInt_FromLong((long)obj->data->GetLaunchProfiles().size());
}

PyObject *
MachineProfile_AddLaunchProfiles(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *element = NULL;
    if(!PyArg_ParseTuple(args, "O", &element))
        return NULL;
    if(!PyLaunchProfile_Check(element))
        return PyErr_Format(PyExc_TypeError, "expected attr object of type LaunchProfile");
    LaunchProfile *newData = PyLaunchProfile_FromPyObject(element);
    obj->data->AddLaunchProfiles(*newData);
    obj->data->SelectLaunchProfiles();
    Py_INCREF(Py_None);
    return Py_None;
}

static PyObject *
MachineProfile_Remove_One_LaunchProfiles(PyObject *self, int index)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    // Remove in the AttributeGroupVector instead of calling RemoveLaunchProfiles() because we don't want to delete the object; just remove it.
    AttributeGroupVector &atts = obj->data->GetLaunchProfiles();
    AttributeGroupVector::iterator pos = atts.begin();
    // Iterate through the vector "index" times.
    for(int i = 0; i < index; ++i)
        ++pos;

    // If pos is still a valid iterator, remove that element.
    if(pos != atts.end())
    {
        // NOTE: Leak the object since other Python objects may reference it. Ideally,
        // we would put the object into some type of pool to be cleaned up later but
        // this will do for now.
        //
        // delete *pos;
        atts.erase(pos);
    }

    obj->data->SelectLaunchProfiles();
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject *
MachineProfile_RemoveLaunchProfiles(PyObject *self, PyObject *args)
{
    int index = -1;
    if(!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "Expecting integer index");
    MachineProfileObject *obj = (MachineProfileObject *)self;
    if(index < 0 || index >= obj->data->GetNumLaunchProfiles())
        return PyErr_Format(PyExc_IndexError, "Index out of range");

    return MachineProfile_Remove_One_LaunchProfiles(self, index);
}

PyObject *
MachineProfile_ClearLaunchProfiles(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    int n = obj->data->GetNumLaunchProfiles();
    for(int i = 0; i < n; ++i)
    {
        MachineProfile_Remove_One_LaunchProfiles(self, 0);
        Py_DECREF(Py_None);
    }
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_SetActiveProfile(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the activeProfile in the object.
    obj->data->SetActiveProfile(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MachineProfile_GetActiveProfile(PyObject *self, PyObject *args)
{
    MachineProfileObject *obj = (MachineProfileObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetActiveProfile()));
    return retval;
}



PyMethodDef PyMachineProfile_methods[MACHINEPROFILE_NMETH] = {
    {"Notify", MachineProfile_Notify, METH_VARARGS},
    {"SetHost", MachineProfile_SetHost, METH_VARARGS},
    {"GetHost", MachineProfile_GetHost, METH_VARARGS},
    {"SetUserName", MachineProfile_SetUserName, METH_VARARGS},
    {"GetUserName", MachineProfile_GetUserName, METH_VARARGS},
    {"SetPassword", MachineProfile_SetPassword, METH_VARARGS},
    {"GetPassword", MachineProfile_GetPassword, METH_VARARGS},
    {"SetHostAliases", MachineProfile_SetHostAliases, METH_VARARGS},
    {"GetHostAliases", MachineProfile_GetHostAliases, METH_VARARGS},
    {"SetHostNickname", MachineProfile_SetHostNickname, METH_VARARGS},
    {"GetHostNickname", MachineProfile_GetHostNickname, METH_VARARGS},
    {"SetDirectory", MachineProfile_SetDirectory, METH_VARARGS},
    {"GetDirectory", MachineProfile_GetDirectory, METH_VARARGS},
    {"SetShareOneBatchJob", MachineProfile_SetShareOneBatchJob, METH_VARARGS},
    {"GetShareOneBatchJob", MachineProfile_GetShareOneBatchJob, METH_VARARGS},
    {"SetSshPortSpecified", MachineProfile_SetSshPortSpecified, METH_VARARGS},
    {"GetSshPortSpecified", MachineProfile_GetSshPortSpecified, METH_VARARGS},
    {"SetSshPort", MachineProfile_SetSshPort, METH_VARARGS},
    {"GetSshPort", MachineProfile_GetSshPort, METH_VARARGS},
    {"SetSshCommandSpecified", MachineProfile_SetSshCommandSpecified, METH_VARARGS},
    {"GetSshCommandSpecified", MachineProfile_GetSshCommandSpecified, METH_VARARGS},
    {"SetSshCommand", MachineProfile_SetSshCommand, METH_VARARGS},
    {"GetSshCommand", MachineProfile_GetSshCommand, METH_VARARGS},
    {"SetUseGateway", MachineProfile_SetUseGateway, METH_VARARGS},
    {"GetUseGateway", MachineProfile_GetUseGateway, METH_VARARGS},
    {"SetGatewayHost", MachineProfile_SetGatewayHost, METH_VARARGS},
    {"GetGatewayHost", MachineProfile_GetGatewayHost, METH_VARARGS},
    {"SetClientHostDetermination", MachineProfile_SetClientHostDetermination, METH_VARARGS},
    {"GetClientHostDetermination", MachineProfile_GetClientHostDetermination, METH_VARARGS},
    {"SetManualClientHostName", MachineProfile_SetManualClientHostName, METH_VARARGS},
    {"GetManualClientHostName", MachineProfile_GetManualClientHostName, METH_VARARGS},
    {"SetTunnelSSH", MachineProfile_SetTunnelSSH, METH_VARARGS},
    {"GetTunnelSSH", MachineProfile_GetTunnelSSH, METH_VARARGS},
    {"SetMaximumNodesValid", MachineProfile_SetMaximumNodesValid, METH_VARARGS},
    {"GetMaximumNodesValid", MachineProfile_GetMaximumNodesValid, METH_VARARGS},
    {"SetMaximumNodes", MachineProfile_SetMaximumNodes, METH_VARARGS},
    {"GetMaximumNodes", MachineProfile_GetMaximumNodes, METH_VARARGS},
    {"SetMaximumProcessorsValid", MachineProfile_SetMaximumProcessorsValid, METH_VARARGS},
    {"GetMaximumProcessorsValid", MachineProfile_GetMaximumProcessorsValid, METH_VARARGS},
    {"SetMaximumProcessors", MachineProfile_SetMaximumProcessors, METH_VARARGS},
    {"GetMaximumProcessors", MachineProfile_GetMaximumProcessors, METH_VARARGS},
    {"GetLaunchProfiles", MachineProfile_GetLaunchProfiles, METH_VARARGS},
    {"GetNumLaunchProfiles", MachineProfile_GetNumLaunchProfiles, METH_VARARGS},
    {"AddLaunchProfiles", MachineProfile_AddLaunchProfiles, METH_VARARGS},
    {"RemoveLaunchProfiles", MachineProfile_RemoveLaunchProfiles, METH_VARARGS},
    {"ClearLaunchProfiles", MachineProfile_ClearLaunchProfiles, METH_VARARGS},
    {"SetActiveProfile", MachineProfile_SetActiveProfile, METH_VARARGS},
    {"GetActiveProfile", MachineProfile_GetActiveProfile, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
MachineProfile_dealloc(PyObject *v)
{
   MachineProfileObject *obj = (MachineProfileObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *MachineProfile_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyMachineProfile_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "host") == 0)
        return MachineProfile_GetHost(self, NULL);
    if(strcmp(name, "userName") == 0)
        return MachineProfile_GetUserName(self, NULL);
    if(strcmp(name, "password") == 0)
        return MachineProfile_GetPassword(self, NULL);
    if(strcmp(name, "hostAliases") == 0)
        return MachineProfile_GetHostAliases(self, NULL);
    if(strcmp(name, "hostNickname") == 0)
        return MachineProfile_GetHostNickname(self, NULL);
    if(strcmp(name, "directory") == 0)
        return MachineProfile_GetDirectory(self, NULL);
    if(strcmp(name, "shareOneBatchJob") == 0)
        return MachineProfile_GetShareOneBatchJob(self, NULL);
    if(strcmp(name, "sshPortSpecified") == 0)
        return MachineProfile_GetSshPortSpecified(self, NULL);
    if(strcmp(name, "sshPort") == 0)
        return MachineProfile_GetSshPort(self, NULL);
    if(strcmp(name, "sshCommandSpecified") == 0)
        return MachineProfile_GetSshCommandSpecified(self, NULL);
    if(strcmp(name, "sshCommand") == 0)
        return MachineProfile_GetSshCommand(self, NULL);
    if(strcmp(name, "useGateway") == 0)
        return MachineProfile_GetUseGateway(self, NULL);
    if(strcmp(name, "gatewayHost") == 0)
        return MachineProfile_GetGatewayHost(self, NULL);
    if(strcmp(name, "clientHostDetermination") == 0)
        return MachineProfile_GetClientHostDetermination(self, NULL);
    if(strcmp(name, "MachineName") == 0)
        return PyInt_FromLong(long(MachineProfile::MachineName));
    if(strcmp(name, "ManuallySpecified") == 0)
        return PyInt_FromLong(long(MachineProfile::ManuallySpecified));
    if(strcmp(name, "ParsedFromSSHCLIENT") == 0)
        return PyInt_FromLong(long(MachineProfile::ParsedFromSSHCLIENT));

    if(strcmp(name, "manualClientHostName") == 0)
        return MachineProfile_GetManualClientHostName(self, NULL);
    if(strcmp(name, "tunnelSSH") == 0)
        return MachineProfile_GetTunnelSSH(self, NULL);
    if(strcmp(name, "maximumNodesValid") == 0)
        return MachineProfile_GetMaximumNodesValid(self, NULL);
    if(strcmp(name, "maximumNodes") == 0)
        return MachineProfile_GetMaximumNodes(self, NULL);
    if(strcmp(name, "maximumProcessorsValid") == 0)
        return MachineProfile_GetMaximumProcessorsValid(self, NULL);
    if(strcmp(name, "maximumProcessors") == 0)
        return MachineProfile_GetMaximumProcessors(self, NULL);
    if(strcmp(name, "launchProfiles") == 0)
        return MachineProfile_GetLaunchProfiles(self, NULL);
    if(strcmp(name, "activeProfile") == 0)
        return MachineProfile_GetActiveProfile(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyMachineProfile_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyMachineProfile_methods[i].ml_name),
                PyString_FromString(PyMachineProfile_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyMachineProfile_methods, self, name);
}

int
PyMachineProfile_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "host") == 0)
        obj = MachineProfile_SetHost(self, args);
    else if(strcmp(name, "userName") == 0)
        obj = MachineProfile_SetUserName(self, args);
    else if(strcmp(name, "password") == 0)
        obj = MachineProfile_SetPassword(self, args);
    else if(strcmp(name, "hostAliases") == 0)
        obj = MachineProfile_SetHostAliases(self, args);
    else if(strcmp(name, "hostNickname") == 0)
        obj = MachineProfile_SetHostNickname(self, args);
    else if(strcmp(name, "directory") == 0)
        obj = MachineProfile_SetDirectory(self, args);
    else if(strcmp(name, "shareOneBatchJob") == 0)
        obj = MachineProfile_SetShareOneBatchJob(self, args);
    else if(strcmp(name, "sshPortSpecified") == 0)
        obj = MachineProfile_SetSshPortSpecified(self, args);
    else if(strcmp(name, "sshPort") == 0)
        obj = MachineProfile_SetSshPort(self, args);
    else if(strcmp(name, "sshCommandSpecified") == 0)
        obj = MachineProfile_SetSshCommandSpecified(self, args);
    else if(strcmp(name, "sshCommand") == 0)
        obj = MachineProfile_SetSshCommand(self, args);
    else if(strcmp(name, "useGateway") == 0)
        obj = MachineProfile_SetUseGateway(self, args);
    else if(strcmp(name, "gatewayHost") == 0)
        obj = MachineProfile_SetGatewayHost(self, args);
    else if(strcmp(name, "clientHostDetermination") == 0)
        obj = MachineProfile_SetClientHostDetermination(self, args);
    else if(strcmp(name, "manualClientHostName") == 0)
        obj = MachineProfile_SetManualClientHostName(self, args);
    else if(strcmp(name, "tunnelSSH") == 0)
        obj = MachineProfile_SetTunnelSSH(self, args);
    else if(strcmp(name, "maximumNodesValid") == 0)
        obj = MachineProfile_SetMaximumNodesValid(self, args);
    else if(strcmp(name, "maximumNodes") == 0)
        obj = MachineProfile_SetMaximumNodes(self, args);
    else if(strcmp(name, "maximumProcessorsValid") == 0)
        obj = MachineProfile_SetMaximumProcessorsValid(self, args);
    else if(strcmp(name, "maximumProcessors") == 0)
        obj = MachineProfile_SetMaximumProcessors(self, args);
    else if(strcmp(name, "activeProfile") == 0)
        obj = MachineProfile_SetActiveProfile(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
MachineProfile_print(PyObject *v, FILE *fp, int flags)
{
    MachineProfileObject *obj = (MachineProfileObject *)v;
    fprintf(fp, "%s", PyMachineProfile_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
MachineProfile_str(PyObject *v)
{
    MachineProfileObject *obj = (MachineProfileObject *)v;
    return PyString_FromString(PyMachineProfile_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *MachineProfile_Purpose = "This class contains information about a host for a remote VisIt engine.";
#else
static char *MachineProfile_Purpose = "This class contains information about a host for a remote VisIt engine.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(MachineProfileType,         \
                  "MachineProfile",           \
                  MachineProfileObject,       \
                  MachineProfile_dealloc,     \
                  MachineProfile_print,       \
                  PyMachineProfile_getattr,   \
                  PyMachineProfile_setattr,   \
                  MachineProfile_str,         \
                  MachineProfile_Purpose,     \
                  MachineProfile_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
MachineProfile_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &MachineProfileType
         || Py_TYPE(other) != &MachineProfileType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    MachineProfile *a = ((MachineProfileObject *)self)->data;
    MachineProfile *b = ((MachineProfileObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static MachineProfile *defaultAtts = 0;
static MachineProfile *currentAtts = 0;

static PyObject *
NewMachineProfile(int useCurrent)
{
    MachineProfileObject *newObject;
    newObject = PyObject_NEW(MachineProfileObject, &MachineProfileType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new MachineProfile(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new MachineProfile(*defaultAtts);
    else
        newObject->data = new MachineProfile;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapMachineProfile(const MachineProfile *attr)
{
    MachineProfileObject *newObject;
    newObject = PyObject_NEW(MachineProfileObject, &MachineProfileType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (MachineProfile *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
MachineProfile_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewMachineProfile(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef MachineProfileMethods[] = {
    {"MachineProfile", MachineProfile_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *MachineProfileObserver = 0;

std::string
PyMachineProfile_GetLogString()
{
    std::string s("MachineProfile = MachineProfile()\n");
    if(currentAtts != 0)
        s += PyMachineProfile_ToString(currentAtts, "MachineProfile.", true);
    return s;
}

static void
PyMachineProfile_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("MachineProfile = MachineProfile()\n");
        s += PyMachineProfile_ToString(currentAtts, "MachineProfile.", true);
        cb(s);
    }
}

void
PyMachineProfile_StartUp(MachineProfile *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyMachineProfile_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(MachineProfileObserver == 0)
    {
        MachineProfileObserver = new ObserverToCallback(subj,
            PyMachineProfile_CallLogRoutine, (void *)data);
    }

}

void
PyMachineProfile_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete MachineProfileObserver;
    MachineProfileObserver = 0;
}

PyMethodDef *
PyMachineProfile_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return MachineProfileMethods;
}

bool
PyMachineProfile_Check(PyObject *obj)
{
    return (obj->ob_type == &MachineProfileType);
}

MachineProfile *
PyMachineProfile_FromPyObject(PyObject *obj)
{
    MachineProfileObject *obj2 = (MachineProfileObject *)obj;
    return obj2->data;
}

PyObject *
PyMachineProfile_New()
{
    return NewMachineProfile(0);
}

PyObject *
PyMachineProfile_Wrap(const MachineProfile *attr)
{
    return WrapMachineProfile(attr);
}

void
PyMachineProfile_SetParent(PyObject *obj, PyObject *parent)
{
    MachineProfileObject *obj2 = (MachineProfileObject *)obj;
    obj2->parent = parent;
}

void
PyMachineProfile_SetDefaults(const MachineProfile *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new MachineProfile(*atts);
}

